<template>
  <div id="app">
    <div v-for="item in news" :key="item.id" class="news-item" @click="onClickNewsItem(item)">
      <div class="title">{{ item.title }}</div>
      <div class="summary">{{ item.summary }}</div>
      <div class="info">
        <div class="time">{{ formatTime(item.updatedAt) }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import JSBridge from '../../../common/jsbridge'
import news from '../news.json'
import dayjs from 'dayjs'

export default {
  name: 'App',
  components: {
  },
  data() {
    return {
      news: [],
    }
  },
  created() {
    // 真实情况这里是通过ajax请求获取
    this.news = news.data
  },
  methods: {
    formatTime(time) {
      return dayjs(time).format('MM月DD日 HH:mm')
    },
    onClickNewsItem(item) {
      JSBridge.Navigation.push({
        page: 'detail.html',
        params: {
          id: item.id,
        },
      })
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  padding: 8px;
}

.title {
  font-weight: bold;
  font-size: 16px;
  text-align: left;
  color: #2c3e50;
}

.news-item {
  padding: 5px;
  border-bottom: 1px solid #f1f1f1;
  margin-top: 5px;
}

.summary {
  margin-top: 5px;
  color: #999;
  font-size: 14px;
  text-align: left;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.info {
  padding: 5px 0px;
}

.info .time {
  text-align: left;
  font-size: 12px;
  color: #aaa;
}
</style>
